/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.assets.shooterstates;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.templates.assets.statemachine.State;
import edu.wpi.first.wpilibj.templates.assets.statemachine.StateMachine;
import edu.wpi.first.wpilibj.templates.commands.CommandBase;

/**
 *
 * @author Jarrod Risley
 */
public class SpinUpShooterState extends State {

    /*
     * Global Class Variables
     */
    protected static SpinUpShooterState SPIN_UP =
            new SpinUpShooterState("Spinning up.");
    
    private double startTime;
    
    // CONSTRUCTOR //
    
    
    protected SpinUpShooterState(String name) {
        super(name);
    } // end SpinUpShooterState Constructor
    
    protected void runFirst() {
        setNext(ZingStateMachine.SHOOT);
    } // end runFirst

    protected void run() {
        
        System.out.println(this + " running.");
        
        startTime = Timer.getFPGATimestamp();
        
        do {
            CommandBase.shooter.spinUpShooter();
        } while (startTime + 2 > Timer.getFPGATimestamp());
        
        setFinished();
        CommandBase.shooter.spinUpShooter();
        
    } // end run

    protected void runLast() {
    } // end runLast

    protected boolean isFinished() {
        return getFinished();
    } // end isFinished

    protected void end() {
        
        System.out.println(this + " ending.");
        
    } // end end...lolz

    protected State getChainedInstance(State nextState) {
        
        SPIN_UP.setNext(nextState);
        return SPIN_UP;
        
    } // end getChainedInstance
    
    
    
} // end SpinUpShooterState
